﻿Imports System.Data.SqlClient
Public Class autobutton

    Dim cmd As New SqlCommand
    Private Sub autobutton_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        condb()
        cmd.Connection = cn
        cmd.CommandText = "select count(*)proName from tblproduct"
        Dim rd = cmd.ExecuteScalar
        Dim a As Integer
        a = rd
        cmd.Connection = cn
        cmd.CommandText = "select proName from tblproduct"
        Dim r = cmd.ExecuteReader
        For i = 1 To a
            Dim btn As New Button
            AddHandler btn.Click, AddressOf clickme
            btn.Image = System.Drawing.Image.FromFile("E:\C# code\Project stock\Image\Untitled-1.png")
            btn.BackColor = Color.Transparent
            btn.FlatStyle = FlatStyle.Popup
            btn.FlatAppearance.BorderSize = 0
            btn.FlatAppearance.BorderColor = Color.Silver
            btn.ForeColor = Color.White
            btn.Cursor = Cursors.Hand
            btn.Font = New Font("Consolas", 14, FontStyle.Regular)
            btn.Width = 70
            btn.Height = 50
            btn.Text = r.Read = True
            btn.Visible = True
            btn.Tag = "Button" & r.ToString
            penellayout.Controls.Add(btn)
        Next

    End Sub
    Private Sub clickme(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim btn As Button
        btn = CType(sender, Button)
        Dim str As String = btn.Text
        Order.ShowDialog()

    End Sub
End Class